package com.huifer.wgx.spec;

import com.huifer.wgx.model.FileEntity;
import com.huifer.wgx.repository.FileRepository;
import java.util.List;
import org.springframework.data.jpa.domain.Specification;

/**
 * <p>Title : CommonSpec </p>
 * <p>Description : </p>
 *
 * @author huifer
 * @date 2019-03-20
 */
public class CommonSpec {



    public static FileEntity fileSpec(FileRepository fileRepository,Long personnelId, Long workid,
            String filename) {
        Specification<FileEntity> spec = (Specification<FileEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
                .and(
                        criteriaBuilder.equal(root.get("personnelId"), personnelId),
                        criteriaBuilder.equal(root.get("workId"), workid),
                        criteriaBuilder.equal(root.get("fileName"), filename)
                );
        List<FileEntity> all = fileRepository.findAll(spec);
        return all.get(all.size() - 1);
    }
}
